/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/house-robber
   @Language: C++
   @Datetime: 20-01-06 11:39
   */

class Solution {
public:
	int rob(vector<int>& nums) {
		int robbed=0, unrobbed=0;
		for(const int &cash:nums){
			int r = unrobbed+cash;
			int u = max(robbed, unrobbed);
			robbed = r;
			unrobbed = u;
		}
		return max(robbed, unrobbed);
	}
};
